{template header}
<link rel="stylesheet" href="static/calendar/js/calendar.css" />
<script type="text/javascript" charset="utf-8" src="static/calendar/calendar.php"></script>
<style type="text/css">
    .bg{display:none;position:fixed;width:100%;height:100%;background:#000;z-index:2;top:0;left:0;opacity:0.7;}
</style>
<h4 style="padding-left:10px;;">
    <span>商品列表 >>
        <a class="" href="?c=adminFlashBuy&a=addFlashBuy" target="_blank">+新建</a>
    </span>
</h4>
<form class="form-horizontal" method="POST" action="?c=adminFlashBuy&a=getFlashList"  >
    <div class="control-group search-group" style="margin:0;padding:0">
        <label class="control-label" >货品名：</label>
        <div class="controls">
            <input type="text" value="{$name}" name="name" placeholder="闪购名" />
            <input type="text" value="{$code}" name="code" placeholder="闪购编号" style="display: none;" />
        </div>
    </div>
    <div class="control-group search-group" style="display: none;" >
        <label class="control-label" >开始时间：</label>
        <div class="controls">
            <input type="text" name="startTime" id="date_time_id" value="{$startTime}">　
            <button name="date_time_btn" type="button" id="date_time_btn" onclick="return showCalendar('date_time_id', '%Y-%m-%d %H:%M:%S', '24', false, 'date_time_btn');" class="button" id="date_time_id"/>选择</button>
        </div>
    </div>
    <div class="control-group search-group" style="display: none;">
        <label class="control-label" >结束时间：</label>
        <div class="controls">
            <input type="text" name="endTime" id="date_time_id2" value="{$endTime}">　
            <button name="date_time_btn2" type="button" id="date_time_btn2" onclick="return showCalendar('date_time_id2', '%Y-%m-%d %H:%M:%S', '24', false, 'date_time_btn2');" class="button" id="date_time_id2"/>选择</button>
        </div>
    </div>

    <div class="control-group search-group" style="margin:0;padding:0">
        <label class="control-label" >类型：</label>
        <div class="controls">
            <select name="type" id="type">
                <option value="0">全部</option>
                <option value="1" {if $type == 1}selected{/if}>自营团购</option>
                <option value="2" {if $type == 2}selected{/if}>识货团购</option>
                <option value="3" {if $type == 3}selected{/if}>直卖</option>
                <option value="4" {if $type == 4}selected{/if}>海淘</option>
            </select>

        </div>
    </div>
    
    <div class="control-group search-group" style="margin:0;padding:0">
        <label class="control-label" >状态：</label>
        <div class="controls">
            <select name="status" id="status">
                <option value="0">全部</option>
                <option value="1" {if $status == 1}selected{/if}>未开始</option>
                <option value="2" {if $status == 2}selected{/if}>进行中</option>
                <option value="3" {if $status == 3}selected{/if}>已结束</option>
            </select>

        </div>
    </div>


    <div class="control-group search-group" style="margin:0;padding:0">
        <div class="controls">
            <input class="btn" type="submit" value="查询" />
        </div>
    </div>

</form>

<div class="bs-docs-example table-align pt-15" style="clear:both;">
    <table class="table table-striped ">
        <thead>
        <tr>
            <th>ID</th>
            <th>图片</th>
            <th>名称</th>
            <th style="display: none;">关联库存</th>
            <th width="100">价格</th>
            <th width="100">关联装备</th>
            <th width="100">类型</th>
            <th width="100">状态</th>
            <th width="100">操作</th>
        </tr>
        </thead>
        {if count($info)>0}
        <tbody>
        {loop $info $k $v}
            <tr>
                <td>{$v['id']}</td>
                <td><img src="{$v['image']}" width="50" height="50"> </td>
                <td>{$v['title']}</td>
                <td>{$v['low_price']}</td>
                <td>{$v['gear_id']}</td>
                <td style="display: none;">{$v['goodsNameList']}</td>
                <td>
                    {if $v['type'] == 1}自营团购{/if}
                    {if $v['type'] == 2}识货团购{/if}
                    {if $v['type'] == 3}直卖{/if}
                    {if $v['type'] == 4}海淘{/if}
                </td>
                <td>{$v['statusMsg']}</td>
                <td style="text-align: left;">
                    <!--<a href="?c=adminErp&a=getProductDetail&pid={$v['id']}">详情</a>-->
                    <!--<a href="?c=adminErp&a=getProductStandard&pid={$v['id']}">补货</a>-->
                    {if $v['type'] != 4}
                        {if $v['is_featured']}
                        <a href="?c=adminFlashBuy&a=setFeatured&is_featured=0&flashId={$v['id']}">取消今日主打</a>
                        {else}
                        <a href="?c=adminFlashBuy&a=setFeatured&is_featured=1&flashId={$v['id']}">设为今日主打</a>
                        {/if}
                        <a href="?c=adminFlashBuy&a=addFlashBuy&flashId={$v['id']}">编辑</a>
                        <a href="javascript:void(0);" id="delLog_{$v['id']}" ids="{$v['id']}" >删除</a>
                        {if $v['status'] == 5}
                            <a href="javascript:void(0);" id="overLog_{$v['id']}" ids="{$v['id']}" >立即结束</a>
                        {/if}

                        <a href="?c=adminFlashBuy&a=addFlashGoods&flashId={$v['id']}" style="display: none">商品配置</a>
                        <a href="?c=admin&a=orderList&s=search&act_type=5&act_id={$v['id']}">订单管理</a>
                        <a href="?c=adminErp&a=getErpProductList&code={$v['pcode']}">库存管理</a>
                    {/if}
                </td>
            </tr>

        {/loop}
        <div id="res"></div>
        </tbody>
        {/if}
    </table>

</div>
<div class="pagination">
    <ul>
        {$pageStr}
    </ul>
</div>
{template footer}
<div class="bg" id="bgx"></div>
<div id="dialog" style="position: absolute; z-index: 1003;background-color:white; display: none;" >
    <div  style="margin:50px 100px;">
        <div class="controls">
            <div style="padding-left:20px;">确定操作？</div><br />
            <div style="text-align: center">
               <button class="btn btn-primary" id="ok" ids="">确定</button>
               <button class="btn btn-primary" id="close" >取消</button>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    $("a[id^='delLog_']").on('click',function () {
        var _this = $(this), _ids = _this.attr('ids');
        $("#bgx").show();
        letDivCenter('#dialog');
        $('#ok').attr({ids:_ids, action:'?c=adminFlashBuy&a=ajaxDelFlashBuy'});
    })

    $("a[id^='overLog_']").on('click',function () {
        var _this = $(this), _ids = _this.attr('ids');
        $("#bgx").show();
        letDivCenter('#dialog');
        $('#ok').attr({ids:_ids, action:'?c=adminFlashBuy&a=ajaxOverFlashBuy'});
    })
    $('#ok').on('click',function(){
        var _this = $(this),ids=_this.attr('ids'), action=_this.attr('action');
        $.ajax({
            type:'POST',
            url:action,
            data:{flashId:ids,status:status},
            dataType:'json',
            success:function(d){
                if(d.status=='ok'){
                    alert(d.error_msg);
                    window.location.reload();
                }else{
                    $('#close').click();
                    alert(d.error_msg);
                }
            }
        })
    })
    $('#close').on('click',function(){
        $('#dialog').css('display','none');
        $("#bgx").fadeOut(300);
    })
    function letDivCenter(divName){
        var divObj = $(divName);
        var wWidth = $(document.body).width(),wHeight = $(window).height();
        var divWidth = divObj.width(),divHeight = divObj.height();
        divObj.css({'left':(wWidth-divWidth)/2+$(window).scrollLeft(),'top':(wHeight-divHeight)/2+$(window).scrollTop(),'display':'block'});
        $(window).bind('scroll resize',function(){
            $(divName).css({'left':(wWidth-divWidth)/2+$(window).scrollLeft(),'top':(wHeight-divHeight)/2+$(window).scrollTop()});
        });
    }

</script>